/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Leoz
 */
@Entity
@Table(name = "movie")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Movie.findAll", query = "SELECT m FROM Movie m"),
    @NamedQuery(name = "Movie.findByIdMovie", query = "SELECT m FROM Movie m WHERE m.moviePK.idMovie = :idMovie"),
    @NamedQuery(name = "Movie.findByName", query = "SELECT m FROM Movie m WHERE m.name = :name"),
    @NamedQuery(name = "Movie.findByYear", query = "SELECT m FROM Movie m WHERE m.year = :year"),
    @NamedQuery(name = "Movie.findByCover", query = "SELECT m FROM Movie m WHERE m.cover = :cover"),
    @NamedQuery(name = "Movie.findByPlotKeywords", query = "SELECT m FROM Movie m WHERE m.plotKeywords = :plotKeywords"),
    @NamedQuery(name = "Movie.findByGenre", query = "SELECT m FROM Movie m WHERE m.genre = :genre"),
    @NamedQuery(name = "Movie.findByRating", query = "SELECT m FROM Movie m WHERE m.rating = :rating"),
    @NamedQuery(name = "Movie.findByDuration", query = "SELECT m FROM Movie m WHERE m.duration = :duration"),
    @NamedQuery(name = "Movie.findByAvailableForRental", query = "SELECT m FROM Movie m WHERE m.availableForRental = :availableForRental"),
    @NamedQuery(name = "Movie.findByAvailableForPurchase", query = "SELECT m FROM Movie m WHERE m.availableForPurchase = :availableForPurchase"),
    @NamedQuery(name = "Movie.findBySoundtrackidSoundtrack", query = "SELECT m FROM Movie m WHERE m.moviePK.soundtrackidSoundtrack = :soundtrackidSoundtrack")})
public class Movie implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected MoviePK moviePK;
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    @Basic(optional = false)
    @Column(name = "year")
    private int year;
    @Basic(optional = false)
    @Column(name = "cover")
    private String cover;
    @Basic(optional = false)
    @Column(name = "plotKeywords")
    private String plotKeywords;
    @Basic(optional = false)
    @Column(name = "genre")
    private String genre;
    @Basic(optional = false)
    @Column(name = "rating")
    private float rating;
    @Basic(optional = false)
    @Column(name = "duration")
    private float duration;
    @Basic(optional = false)
    @Column(name = "availableForRental")
    private boolean availableForRental;
    @Basic(optional = false)
    @Column(name = "availableForPurchase")
    private boolean availableForPurchase;
    @ManyToMany(mappedBy = "movieCollection")
    private Collection<Actor> actorCollection;
    @JoinColumn(name = "Soundtrack_idSoundtrack", referencedColumnName = "idSoundtrack", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Soundtrack soundtrack;
    @JoinColumn(name = "Director_idDirector", referencedColumnName = "idDirector")
    @ManyToOne(optional = false)
    private Director directoridDirector;

    public Movie() {
    }

    public Movie(MoviePK moviePK) {
        this.moviePK = moviePK;
    }

    public Movie(MoviePK moviePK, String name, int year, String cover, String plotKeywords, String genre, float rating, float duration, boolean availableForRental, boolean availableForPurchase) {
        this.moviePK = moviePK;
        this.name = name;
        this.year = year;
        this.cover = cover;
        this.plotKeywords = plotKeywords;
        this.genre = genre;
        this.rating = rating;
        this.duration = duration;
        this.availableForRental = availableForRental;
        this.availableForPurchase = availableForPurchase;
    }

    public Movie(int idMovie, int soundtrackidSoundtrack) {
        this.moviePK = new MoviePK(idMovie, soundtrackidSoundtrack);
    }

    public MoviePK getMoviePK() {
        return moviePK;
    }

    public void setMoviePK(MoviePK moviePK) {
        this.moviePK = moviePK;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public String getCover() {
        return cover;
    }

    public void setCover(String cover) {
        this.cover = cover;
    }

    public String getPlotKeywords() {
        return plotKeywords;
    }

    public void setPlotKeywords(String plotKeywords) {
        this.plotKeywords = plotKeywords;
    }

    public String getGenre() {
        return genre;
    }

    public void setGenre(String genre) {
        this.genre = genre;
    }

    public float getRating() {
        return rating;
    }

    public void setRating(float rating) {
        this.rating = rating;
    }

    public float getDuration() {
        return duration;
    }

    public void setDuration(float duration) {
        this.duration = duration;
    }

    public boolean getAvailableForRental() {
        return availableForRental;
    }

    public void setAvailableForRental(boolean availableForRental) {
        this.availableForRental = availableForRental;
    }

    public boolean getAvailableForPurchase() {
        return availableForPurchase;
    }

    public void setAvailableForPurchase(boolean availableForPurchase) {
        this.availableForPurchase = availableForPurchase;
    }

    @XmlTransient
    public Collection<Actor> getActorCollection() {
        return actorCollection;
    }

    public void setActorCollection(Collection<Actor> actorCollection) {
        this.actorCollection = actorCollection;
    }

    public Soundtrack getSoundtrack() {
        return soundtrack;
    }

    public void setSoundtrack(Soundtrack soundtrack) {
        this.soundtrack = soundtrack;
    }

    public Director getDirectoridDirector() {
        return directoridDirector;
    }

    public void setDirectoridDirector(Director directoridDirector) {
        this.directoridDirector = directoridDirector;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (moviePK != null ? moviePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Movie)) {
            return false;
        }
        Movie other = (Movie) object;
        if ((this.moviePK == null && other.moviePK != null) || (this.moviePK != null && !this.moviePK.equals(other.moviePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entidades.Movie[ moviePK=" + moviePK + " ]";
    }
    
}
